/***************************************
*** gestiune xmlDocument client-side ***
****************************************/

function editPara(parentId,id){
	var div=document.getElementById(parentId);
	var menuInitClass=div.className;
	div.setAttribute('onclick','null');
	var para=document.getElementById(id);
	var txt=para.innerHTML;

	div.className="editParagraf";
	var textArea=document.createElement('textarea');
	textArea.innerHTML=txt;
	textArea.setAttribute('id','txtArr');
	textArea.setAttribute('class','editor');
	//textArea.setAttribute('onchange', 'setTxtArrVal(this.id)');

	var menu=document.createElement('table');
	menu.setAttribute('id','jsCntxEditorMenu');
	menu.setAttribute('align','center');
	menu.setAttribute('border','1');
	menu.setAttribute('class','editParaMenu');
	var tr=document.createElement('tr');
	var tdOk=document.createElement('td');
	tdOk.setAttribute('class','editParaMenu');
	//tdOk.setAttribute('onclick', 'setTxtArrVal('+"'"+textArea.id+"'"+","+"'"parentId+"'"+')');
	tdOk.setAttribute('onclick', 'setTxtArrVal('+"'"+textArea.id+"'"+','+"'"+parentId+"'"+','+"'"+menu.id+"'"+','+"'"+menuInitClass+"'"+')');
	var tdOkTxt=document.createTextNode('Ok');
	tdOk.appendChild(tdOkTxt);
	var tdDel=document.createElement('td');
	tdDel.setAttribute('class','editParaMenu');
	var tdDelTxt=document.createTextNode('Sterge');
	tdDel.appendChild(tdDelTxt);
	tr.appendChild(tdOk);
	tr.appendChild(tdDel);
	menu.appendChild(tr);

	div.replaceChild(textArea, para);
	div.appendChild(menu);
	//textArea.setAttribute('onchange', "setTxtArrVal(this.id,"+"'"+parentId+"'"+')');
}

function setTxtArrVal(txtArrId, divId, menuId, menuInitClass){
	//salvam datele in txtarrea
	var txtArr=document.getElementById(txtArrId);
	var txtArrCont=txtArr.lastChild;
	var newVal=document.createTextNode(txtArr.value);
	txtArr.replaceChild(newVal,txtArrCont);

	var div=document.getElementById(divId);

	var para=document.createElement('p');
	para.setAttribute('id',divId+"p");
	para.setAttribute('onclick','editPara('+"'"+divId+"'"+','+"'"+para.id+"'"+')');
	para.innerHTML=txtArr.value;

	var txtArrea=document.getElementById(txtArrId);
	div.className=menuInitClass;
	menu=document.getElementById(menuId);
	div.removeChild(menu);
	div.replaceChild(para, txtArrea);

	//salvare in DOM changesQueue
	var chapId=document.getElementById('curentChapterId').value;
	editorDocument.docElements[chapId].updateBasicElements(divId, txtArr.value, menuInitClass);
	//alert("sdfsdfsd");
}

//-----------screen freeze--------------

function saveChapterChanges(chapter)
{
	if(editorDocument.docElements[chapter].newElemQueue.length !== 0 || editorDocument.docElements[chapter].changesQueue.length !== 0){
		DarkenPage();
		showSavingChapterChangesPanel(chapter);
		prog();
	}else{
		alert("No changes made!");
	}
}

function showSavingChapterChangesPanel(chapter)
{
	var newsletter_panel = document.getElementById('screenFreeze_panel');
	w = 300;
	h = 160;

	// xc = Math.round((document.body.clientWidth/2)-(w/2));
	// yc = Math.round((document.body.clientHeight/4)-(h/2));
	//xc=Math.round(500-(w/2));
	//	yc=Math.round(250-(h/2));
	xc = Math.round((document.body.clientWidth/2)-(w/2));
	yc = 250;

	newsletter_panel.style.left = xc + "px";
	newsletter_panel.style.top  = yc + "px";
	newsletter_panel.style.display = 'block';
	sendChangeToServer(chapter);
}

function saveChapterChangesEnd(chapter)
{
	var newsletter_panel = document.getElementById('screenFreeze_panel');
	newsletter_panel.style.display = 'none';
	LightenPage();
	//console.dir(editorDocument);
/*	try{
		window.location=document.URL;
	}catch(e){
		alert(e.toString());
	}*/
}

function DarkenPage()
{
	var page_screen = document.getElementById('screenFreeze_screen');
	page_screen.style.height = document.body.parentNode.scrollHeight + 'px';
	page_screen.style.display = 'block';
}

function LightenPage()
{
	var page_screen = document.getElementById('screenFreeze_screen');
	page_screen.style.display = 'none';
}

//++++++++++++editor++++++++++

//creare paragraf nou
function openNewParaPanel(){
	DarkenPage();
	var newParaPanel = document.getElementById('editorElements_panel');
	w = 552;
	xc = Math.round((document.body.clientWidth/2)-(w/2));

	newParaPanel.style.left = xc + "px";
	newParaPanel.style.top  = 100 + "px";
	newParaPanel.style.display = 'block';
}

function newParagraphCancel(){
	var txtArrea=document.getElementById('createNewParaTextarea');
	txtArrea.value='';
	var newParaPanel =document.getElementById('editorElements_panel');
	newParaPanel.style.display = 'none';
	LightenPage();
}

function newParagraphOk(chapterName){
	var txtArr=document.getElementById('createNewParaTextarea');
	var content=txtArr.value;

	if(content !== ''){
		var newParaDiv=document.createElement('div');
		newParaDiv.setAttribute('class','paragraf');
		var paraId=generateRandomNumber();
		newParaDiv.setAttribute('id',paraId);

		var newPara=document.createElement('p');
		newPara.setAttribute('id',paraId+'p');
		newParaDiv.setAttribute("onclick","editPara('"+paraId+"','"+paraId+"p');");
		newPara.appendChild(document.createTextNode(content));
		newParaDiv.appendChild(newPara);

		var helder=document.getElementById('helder');
		helder.appendChild(newParaDiv);

		//adaugare in xmlChapter
		editorDocument.docElements[chapterName].createNewParagraph(paraId, content);
		txtArr.value='';
	}

	var newParaPanel =document.getElementById('editorElements_panel');
	newParaPanel.style.display = 'none';
	LightenPage();
}

//creare nota noua
function openNewNotePanel(){
	DarkenPage();
	var newNotePanel = document.getElementById('editorElementsNote_panel');
	w = 552;
	xc = Math.round((document.body.clientWidth/2)-(w/2));

	newNotePanel.style.left = xc + "px";
	newNotePanel.style.top  = 100 + "px";
	newNotePanel.style.display = 'block';
}

function newNoteCancel(){
	var txtArrea=document.getElementById('createNewNoteTextarea');
	txtArrea.value='';
	var newNotePanel =document.getElementById('editorElementsNote_panel');
	newNotePanel.style.display = 'none';
	LightenPage();
}

function newNoteOk(chapterName){
	var txtArr=document.getElementById('createNewNoteTextarea');
	var content=txtArr.value;

	if(content !== ''){
		var newNoteDiv=document.createElement('div');
		newNoteDiv.setAttribute('class','note');
		var noteId=generateRandomNumber();
		newNoteDiv.setAttribute('id',noteId);

		var newNote=document.createElement('p');
		newNote.setAttribute('id',noteId+'p');
		newNoteDiv.setAttribute("onclick","editPara('"+noteId+"','"+noteId+"p');");
		newNote.appendChild(document.createTextNode(content));
		var newNoteCaption=document.createElement('p');
		newNoteCaption.setAttribute('align','left');
		newNoteCaption.appendChild(document.createTextNode('Note:'));
		newNoteDiv.appendChild(newNoteCaption);
		newNoteDiv.appendChild(newNote);

		var helder=document.getElementById('helder');
		helder.appendChild(newNoteDiv);

		//adaugare in xmlChapter
		//alert(noteId+","+content);
		editorDocument.docElements[chapterName].createNewNote(noteId, content);
		txtArr.value='';
	}

	var newNotePanel =document.getElementById('editorElementsNote_panel');
	newNotePanel.style.display = 'none';
	LightenPage();
}

//progress bar
var progressBarInit=0;
var progressBarRatio=0;
function prog()
{
	document.getElementById("progressBar1").innerHTML="";
	document.getElementById("progressBar2").style.width=0;
	progressBarRatio=parseInt((100/((editorDocument.docElements[currentChapter].newElemQueue.length+1)+(editorDocument.docElements[currentChapter].changesQueue.length+1)))*3);
	progBar();
}

function progBar()
{
	if (progressBarInit <= 300)
	{
		if (progressBarInit>10){
			document.getElementById("progressBar1").innerHTML=parseInt(progressBarInit/3)+"%";
		}
		document.getElementById("progressBar2").style.width=progressBarInit+"px";
		progressBarInit+=progressBarRatio;
	}
}

//editare tabel
function editTableRow(table, rowIndex){
	var row=document.getElementById(table+"_"+rowIndex);

	//update menu
	var size=parseInt(row.cells.length);
	var newTd=document.createElement('td');

	var okDiv=document.createElement('div');
	okDiv.setAttribute('class','editRowMenu');
	okDiv.setAttribute('onclick',"editTableRowSave('"+table+"','"+rowIndex+"');");
	okDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
	okDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
	okDiv.appendChild(document.createTextNode('OK'));
	newTd.appendChild(okDiv);

	row.removeChild(row.cells[size-1]);
	row.appendChild(newTd);

	//replace elements
	for(var i=0; i<size-1; i++){
		var cell=row.cells[i];
		var value=cell.innerHTML;

		var input=document.createElement('input');
		input.setAttribute('value',value);
		input.setAttribute('size','10');

		cell.removeChild(cell.firstChild);
		cell.appendChild(input);
	}
}

function deleteTableRow(table, rowInd){
	//alert(table+" , "+rowIndex);
	var domDiv=document.getElementById(table);
	var domTable=domDiv.firstChild;
	var row=document.getElementById(table+"_"+rowInd).rowIndex;
	domTable.deleteRow(row);
}

function editTableRowSave(table, rowIndex){
	var row=document.getElementById(table+"_"+rowIndex);

	if(rowIndex == 0){
		var domDiv=document.getElementById(table);
		var domTable=domDiv.firstChild;
		var tbody=domTable.lastChild;
		var tableSize=tbody.rows.length+1;
		//var cellNr=tbody.rows[0].cells.length;
		var cellNr=0;
		try{
			cellNr=tbody.rows[0].cells.length;
		}catch(e){
			cellNr=domTable.childNodes[1].rows[0].childNodes.length;
		}

		var newTd=document.createElement('td');
		newTd.setAttribute('class','editorTableHeader');

		var editDiv=document.createElement('div');
		editDiv.setAttribute('class','editRowMenu');
		editDiv.setAttribute('onclick',"editTableRow('"+table+"','0');");
		editDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
		editDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
		editDiv.appendChild(document.createTextNode('Edit'));
		newTd.appendChild(editDiv);

		var addDiv=document.createElement('div');
		addDiv.setAttribute('class','editRowMenu');
		addDiv.setAttribute('onclick',"editTableAddRow('"+table+"');");
		addDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
		addDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
		addDiv.appendChild(document.createTextNode('Add row'));
		newTd.appendChild(addDiv);

		row.removeChild(row.cells[cellNr-1]);
		row.appendChild(newTd);

		//replace elements
		for(var i=0; i<cellNr-1; i++){
			var cell=row.cells[i];
			var input=cell.firstChild;
			var value=input.value;
			//alert(value);
			cell.removeChild(cell.firstChild);
			cell.appendChild(document.createTextNode(value));
		}


	}else{
		//update menu
		var size=parseInt(row.cells.length);
		var newTd=document.createElement('td');

		var editDiv=document.createElement('div');
		editDiv.setAttribute('class','editRowMenu');
		editDiv.setAttribute('onclick',"editTableRow('"+table+"','"+rowIndex+"');");
		editDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
		editDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
		editDiv.appendChild(document.createTextNode('Edit'));
		newTd.appendChild(editDiv);

		var deleteDiv=document.createElement('div');
		deleteDiv.setAttribute('class','editRowMenu');
		deleteDiv.setAttribute('onclick',"deleteTableRow('"+table+"','"+rowIndex+"');");
		deleteDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
		deleteDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
		deleteDiv.appendChild(document.createTextNode('Delete'));
		newTd.appendChild(deleteDiv);

		row.removeChild(row.cells[size-1]);
		row.appendChild(newTd);

		//replace elements
		for(var i=0; i<size-1; i++){
			var cell=row.cells[i];
			var input=cell.firstChild;
			var value=input.value;
			//alert(value);
			cell.removeChild(cell.firstChild);
			cell.appendChild(document.createTextNode(value));
		}
	}
}

//adugare rand nou
function editTableAddRow(table){
	var domDiv=document.getElementById(table);
	var domTable=domDiv.firstChild;
	var tbody=domTable.lastChild;
	var tableSize=tbody.rows.length+1;
	//var cellNr=tbody.rows[0].cells.length;
	var cellNr=0;
	try{
		cellNr=tbody.rows[0].cells.length;
	}catch(e){
		cellNr=domTable.childNodes[1].rows[0].childNodes.length;
	}

	var tr=document.createElement('tr');
	tr.setAttribute('id',table+"_"+tableSize);
	tr.setAttribute('onmouseover',"this.className='editorTableHighlight'");
	tr.setAttribute('onmouseout',"this.className='editorTableNormal'");

	//cells
	for(var i=0; i<cellNr-1; i++){
		var td=document.createElement('td');
		var input=document.createElement('input');
		input.setAttribute('value','');
		input.setAttribute('size','10');

		td.appendChild(input);
		tr.appendChild(td);
	}

	//menu
	var newTd=document.createElement('td');

	var okDiv=document.createElement('div');
	okDiv.setAttribute('class','editRowMenu');
	okDiv.setAttribute('onclick',"editTableRowSave('"+table+"','"+tableSize+"');");
	okDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
	okDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
	okDiv.appendChild(document.createTextNode('OK'));
	newTd.appendChild(okDiv);

	tr.appendChild(newTd);

	tbody.appendChild(tr);
}

function changeTableCaption(table){
	var domDiv=document.getElementById(table);
	var domTable=domDiv.firstChild;
	var caption=domTable.firstChild;
	var captionValue=caption.firstChild.textContent;

	var input=document.createElement('input');
	input.setAttribute('value',captionValue);
	input.setAttribute('size','50');

	var divOk=document.createElement('div');
	divOk.setAttribute('style','background-color: #33FFFF;');
	divOk.setAttribute('onclick',"changeTableCaptionSave('"+table+"');");
	divOk.appendChild(document.createTextNode('OK'));

	caption.removeChild(caption.childNodes[0]);
	caption.appendChild(input);
	caption.appendChild(divOk);
}

function changeTableCaptionSave(table){
	var domDiv=document.getElementById(table);
	var domTable=domDiv.firstChild;
	var caption=domTable.firstChild;
	var captionValue=caption.firstChild.value;
	var chids=caption.childNodes.length;

	caption.removeChild(caption.firstChild);
	caption.removeChild(caption.lastChild);

	var newPara=document.createElement('p');
	newPara.setAttribute('onclick',"changeTableCaption('"+table+"');")
	newPara.appendChild(document.createTextNode(captionValue));
	caption.appendChild(newPara);
	//	alert(captionValue);
}

function openNewTablePanel(){
	DarkenPage();
	var newTablePanel = document.getElementById('editorElementsTable_panel');
	w = 350;
	xc = Math.round((document.body.clientWidth/2)-(w/2));

	newTablePanel.style.left = xc + "px";
	newTablePanel.style.top  = 100 + "px";
	newTablePanel.style.display = 'block';
}

function deleteTable(table){
	var opt=confirm("Are you really sure you want to delete this table ?");
	if(opt == true){
		var helder=document.getElementById('helder');
		var domTable=document.getElementById(table);
		var delButton=document.getElementById("delTab_"+table);

		helder.removeChild(delButton);
		helder.removeChild(domTable);
	}
}

function createNewTableValidatePage1(){
	var domCaption=document.getElementById('createNewTableCaption');
	var domRows=document.getElementById('createNewTableRowsNr');
	var page1=document.getElementById('createNewTableEditorP1');
	var page2=document.getElementById('createNewTableEditorP2');

	//validare nr coloane
	var caption=domCaption.value;
	var rows=parseInt(domRows.value);
	if(caption == ''){
		alert("Titlul tabelului nu a fost completat!!!")
		domCaption.focus();
	}else{
		if(rows == ''){
			alert("Numarul de coloane nu a fost completat!!!")
			domRows.focus();
		}else{
			if(isNaN(rows)){
				alert("Numarul de coloane trebuie sa fie un numar!!!")
				domRows.focus();
			}else{
				if((rows<=0) || (rows >=10)){
					alert("Numarul de coloane trebuie sa fie un numar >=1 si <10 !!!")
					domRows.focus();
				}else{
					page1.className="createNewTableWinHide";

					//adaugare tr
					var editTable=page2.childNodes[0];
					var pastIndex=0;
					try{
						pastIndex=parseInt(document.getElementById('createNewTablePannelRowsNo').value);
					}catch(e){
						pastIndex=0;
					}

					if(editTable.childNodes.length == 0 && pastIndex == 0){

						var captionTr=document.createElement('tr');
						var captionTd=document.createElement('td');
						captionTd.setAttribute('align','center');
						captionTd.setAttribute('colspan','2');
						captionTd.appendChild(document.createTextNode('Header'));
						captionTr.appendChild(captionTd);
						editTable.appendChild(captionTr);

						//for
						for(var i=0; i<rows; i++){
							var newTr=document.createElement('tr');

							var newTd1=document.createElement('td');
							newTd1.setAttribute('align', 'center');
							newTd1.appendChild(document.createTextNode('Col. no: '+i));
							newTr.appendChild(newTd1);

							var newTd2=document.createElement('td');
							newTd2.setAttribute('align', 'center');
							var input=document.createElement('input');
							input.setAttribute('type','text');
							input.setAttribute('onfocus',"this.style.backgroundColor='#CCFFFF'");
							input.setAttribute('onblur',"this.style.backgroundColor='#ffffff'");
							newTd2.appendChild(input);
							newTr.appendChild(newTd2);

							editTable.appendChild(newTr);
						}

						//meniu jos
						var menuTr=document.createElement('tr');

						var menuTdBack=document.createElement('td');
						menuTdBack.setAttribute('align','left');
						menuTdBack.setAttribute('onclick','createNewTableValidatePage2Back();');
						menuTdBack.appendChild(document.createTextNode('<<< Back'));
						menuTr.appendChild(menuTdBack);

						var menuTdFinish=document.createElement('td');
						menuTdFinish.setAttribute('align','right');
						menuTdFinish.setAttribute('onclick','createNewTableValidatePage2Finish();');
						menuTdFinish.appendChild(document.createTextNode('Finish >>>'));
						menuTr.appendChild(menuTdFinish);

						//editTable.appendChild(menuTr);

						var index=document.createElement('input');
						index.setAttribute('type','hidden');
						index.setAttribute('id','createNewTablePannelRowsNo');
						index.setAttribute('value',rows);

						menuTr.appendChild(index);

						editTable.appendChild(menuTr);
					}

					if((pastIndex != 0) && (pastIndex != rows)){
						//remove childrens
						var lungime=editTable.childNodes.length;
						for(var i=0; i<lungime; i++){
							editTable.removeChild(editTable.childNodes[0]);
						}
						var captionTr=document.createElement('tr');
						var captionTd=document.createElement('td');
						captionTd.setAttribute('align','center');
						captionTd.setAttribute('colspan','2');
						captionTd.appendChild(document.createTextNode('Header'));
						captionTr.appendChild(captionTd);
						editTable.appendChild(captionTr);

						//for
						for(var i=0; i<rows; i++){
							var newTr=document.createElement('tr');

							var newTd1=document.createElement('td');
							newTd1.setAttribute('align', 'center');
							newTd1.appendChild(document.createTextNode('Col. no: '+i));
							newTr.appendChild(newTd1);

							var newTd2=document.createElement('td');
							newTd2.setAttribute('align', 'center');
							var input=document.createElement('input');
							input.setAttribute('type','text');
							input.setAttribute('onfocus',"this.style.backgroundColor='#CCFFFF'");
							input.setAttribute('onblur',"this.style.backgroundColor='#ffffff'");
							newTd2.appendChild(input);
							newTr.appendChild(newTd2);

							editTable.appendChild(newTr);
						}

						//meniu jos
						var menuTr=document.createElement('tr');

						var menuTdBack=document.createElement('td');
						menuTdBack.setAttribute('align','left');
						menuTdBack.setAttribute('onclick','createNewTableValidatePage2Back();');
						menuTdBack.appendChild(document.createTextNode('<<< Back'));
						menuTr.appendChild(menuTdBack);

						var menuTdFinish=document.createElement('td');
						menuTdFinish.setAttribute('align','right');
						menuTdFinish.setAttribute('onclick','createNewTableValidatePage2Finish();');
						menuTdFinish.appendChild(document.createTextNode('Finish >>>'));
						menuTr.appendChild(menuTdFinish);

						//editTable.appendChild(menuTr);

						var index=document.createElement('input');
						index.setAttribute('type','hidden');
						index.setAttribute('id','createNewTablePannelRowsNo');
						index.setAttribute('value',rows);

						menuTr.appendChild(index);

						editTable.appendChild(menuTr);
					}

					page2.className="createNewTableWinShow";
				}
			}
		}
	}
}

function createNewTableValidatePage2Back(){
	var page1=document.getElementById('createNewTableEditorP1');
	var page2=document.getElementById('createNewTableEditorP2');
	page1.className="createNewTableWinShow";
	page2.className="createNewTableWinHide";
}

function createNewTableValidatePage2Finish(){
	var page1=document.getElementById("createNewTableEditorP1");
	var page2=document.getElementById("createNewTableEditorP2");

	var title=page1.firstChild.rows[0].cells[1].firstChild.value;
	var colNo=parseInt(page1.firstChild.rows[1].cells[1].firstChild.value);

	var headers=new Array();
	for(var i=0; i<colNo; i++){
		headers[i]=page2.firstChild.childNodes[i+1].cells[1].firstChild.value;
	}

	var helder=document.getElementById('helder');

	var divTable=document.createElement('div');
	var divTableId="t"+Math.ceil(Math.random()*100000);
	divTable.setAttribute('id',divTableId);
	divTable.setAttribute('class','table');

	var table=document.createElement('table');
	table.setAttribute('class','editorTable');
	table.setAttribute('align','center');

	var caption=document.createElement('caption');
	caption.setAttribute('class','editorTable');
	caption.setAttribute('align','bottom');
	var captionPara=document.createElement('p');
	captionPara.setAttribute('onclick',"changeTableCaption('"+divTableId+"')");
	captionPara.appendChild(document.createTextNode(title));
	caption.appendChild(captionPara);

	table.appendChild(caption);

	var thead=document.createElement('thead');
	var theadTr=document.createElement('tr');
	theadTr.setAttribute('id',divTableId+"_0");

	//thead elements
	for(var i=0; i<colNo; i++){
		var td=document.createElement('td');
		td.setAttribute('class','editorTableHeader');
		td.appendChild(document.createTextNode(headers[i]));
		theadTr.appendChild(td);
	}

	//thead menu
	var menuTd=document.createElement('td');
	menuTd.setAttribute('class','editorTableHeader');

	var editDiv=document.createElement('div');
	editDiv.setAttribute('class','editRowMenu');
	editDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
	editDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
	editDiv.setAttribute('onclick',"editTableRow('"+divTableId+"','0')");
	editDiv.appendChild(document.createTextNode('Edit'));

	menuTd.appendChild(editDiv);

	var addDiv=document.createElement('div');
	addDiv.setAttribute('class','editRowMenu');
	addDiv.setAttribute('onmouseout',"this.className='editRowMenu'");
	addDiv.setAttribute('onmouseover',"this.className='editRowMenuHover'");
	addDiv.setAttribute('onclick',"editTableAddRow('"+divTableId+"')");
	addDiv.appendChild(document.createTextNode('Add row'));

	menuTd.appendChild(addDiv);

	theadTr.appendChild(menuTd);
	thead.appendChild(theadTr);

	table.appendChild(thead);

	var tbody=document.createElement('tbody');
	table.appendChild(tbody);

	divTable.appendChild(table);

	//meniu stergere tabel
	var deleteTableDiv=document.createElement('div');
	deleteTableDiv.setAttribute('id',"delTab_"+divTableId);
	deleteTableDiv.setAttribute('class','deleteTable');
	deleteTableDiv.setAttribute('onclick',"deleteTable('"+divTableId+"')");
	deleteTableDiv.setAttribute('onmouseout', "this.className='deleteTable'; this.innerHTML='X'");
	deleteTableDiv.setAttribute('onmouseover', "this.className='deleteTableHover'; this.innerHTML='Delete table'");
	deleteTableDiv.appendChild(document.createTextNode('X'));

	helder.appendChild(deleteTableDiv);
	helder.appendChild(divTable);

	//free panel of data
	page1.firstChild.rows[0].cells[1].firstChild.value='';
	page1.firstChild.rows[1].cells[1].firstChild.value=0;
	for(var i=0; i<colNo; i++){
		page2.firstChild.removeChild(page2.firstChild.childNodes[1]);
	}

	//adaugare in dom
	var chapterName=document.getElementById('createNewTableChapterName').value;
	editorDocument.docElements[chapterName].createNewTable(divTableId, title, headers);

	//refresh frame
	page1.className="createNewTableWinShow";
	page2.className="createNewTableWinHide";

	//light page
	var newTablePanel=document.getElementById('editorElementsTable_panel');
	newTablePanel.style.display = 'none';
	LightenPage();
}

function cleanHelder(){
	var helder=document.getElementById('helder');
	while(helder.hasChildNodes()){
		helder.removeChild(helder.firstChild);
	}
}